package com.simen.hellobytes.strings;

import java.util.ArrayList;
import java.util.List;

public class StringTools {

    public static int count(String source, String str) {
        int index = -1;
        int count = 0;

        while ((index = source.indexOf(str, index + 1)) != -1) {
            count++;
        }

        return count;
    }

    public static int[] indexs(String source, String str) {
        int index = -1;
        List<Integer> indexList = new ArrayList<>();

        while ((index = source.indexOf(str, index + 1)) != -1) {
            indexList.add(index);
        }

        int[] indexs = new int[indexList.size()];
        for (int i = 0; i < indexList.size(); i++) {
            indexs[i] = indexList.get(i);
        }

        return indexs;
    }

}
